package mqtt;

import HslCommunication.Core.Types.ActionOperateExTwo;
import HslCommunication.Core.Types.OperateResultExTwo;
import HslCommunication.MQTT.MqttSyncClient;

import java.text.SimpleDateFormat;
import java.util.Date;

public class MqttSyncClientTest {
    public static void main(String[] args){
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        MqttSyncClient mqttSync = new MqttSyncClient( "127.0.0.1", 1883 );
        mqttSync.SetPersistentConnection( );



//        for (int i = 0; i < 100; i++)
//        {
//            OperateResultExTwo<String, String> readA = mqttSync.ReadString( "D", "测试的数据"+i, null, null, null );
//            System.out.println(readA.IsSuccess);
//
//        }

        for (int i = 0; i < 2; i++)
        {
            OperateResultExTwo<String, String> readB = mqttSync.ReadString( "B", "测试的数据",
                    new ActionOperateExTwo<Long, Long>(){
                        @Override
                        public void Action(Long m, Long n) {
                            System.out.println( formatter.format(new Date()) + " 已发送：" + m + "/" + n);
                        }
                    },
                    new ActionOperateExTwo<String, String>(){
                        @Override
                        public void Action(String m, String n) {
                            System.out.println(formatter.format(new Date()) + " 服务器正在处理:" + m + ", 进度：" + n);
                        }
                    },
                    new ActionOperateExTwo<Long, Long>(){
                        @Override
                        public void Action(Long m, Long n) {
                            System.out.println(formatter.format(new Date()) + " 已接收：" + m + "/" + n);
                        }
                    });
            System.out.println(readB.IsSuccess);
        }

        OperateResultExTwo<String, String> readC = mqttSync.ReadString( "C", "测试的数据",
                new ActionOperateExTwo<Long, Long>(){
                    @Override
                    public void Action(Long m, Long n) {
                        System.out.println( formatter.format(new Date()) + " 已发送：" + m + "/" + n);
                    }
                },
                new ActionOperateExTwo<String, String>(){
                    @Override
                    public void Action(String m, String n) {
                        System.out.println(formatter.format(new Date()) + " 服务器正在处理:" + m + ", 进度：" + n);
                    }
                },
                new ActionOperateExTwo<Long, Long>(){
                    @Override
                    public void Action(Long m, Long n) {
                        System.out.println(formatter.format(new Date()) + " 已接收：" + m + "/" + n);
                    }
                });
        System.out.println(readC.IsSuccess);


        mqttSync.ConnectClose();

    }
}
